<template>
  <el-dialog
    title="审核项目"
    :visible.sync="dialogVisible"
    size="60%"
    custom-class="search-result-pop title-list"
    :before-close="handleClose"
  >
    <div class="audit-project">
      <FormGroup v-if="addColumnConfig" ref="formParams" style="margin-top: 20px" :search-config="addColumnConfig" label-width="120px" label-position="right" />
    </div>
    <div class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" style="margin-left: 50px" @click="handleConfirm">确 定</el-button>
    </div>

  </el-dialog>
</template>
<script>
import { updateNewsStudyTypeSort } from '@/api/content-manage/researchResult.js'
import { updateMessageTypeSort } from '@/api/inner-msg/index.js'
import FormGroup from '@/views/components/FormGroup'
export default {
  name: 'DragSrot',
  components: { FormGroup },
  props: ['TYPE'],
  data() {
    return {
      dialogVisible: false,
      tableList: [],
      auditRadio: '',
      addColumnConfig: [
        {
          type: 'content',
          value: '数据分析项目',
          label: '当前项目',
          keyIndex: 'name',
          placeholder: '输入名称。10字以内',
          span: 24,
          inputWidth: '300px',
          maxlength: 10,
          showWordLimit: true,
          inputType: 'text'
        },
        {
          type: 'radio',
          value: '0',
          label: '审核',
          keyIndex: 'status',
          span: 24,
          options: [
            {
              value: '1',
              label: '通过'
            },
            {
              value: '0',
              label: '驳回'
            }
          ]
        },
        {
          type: 'textarea',
          value: '',
          label: '备注',
          keyIndex: 'name',
          placeholder: '输入备注。500字以内',
          span: 24,
          inputWidth: '300px',
          maxlength: 500,
          showWordLimit: true,
          rows: 5
        }
      ]
    }
  },
  mounted() {
    // 拖拽事件
    this.$dragging.$on('dragged', (result) => {
      // 将排序后的结果重新赋值
      this.tableList = result.value.list
    })
  },
  beforeDestroy() {
    this.$dragging.$off('dragged')
  },
  methods: {
    handleClose() {
      this.dialogVisible = false
      this.tableList = []
      this.$dragging.$off('dragged')
    },
    open() {
      this.dialogVisible = true
    },
    async handleConfirm() {
      const ids = this.tableList.map(v => v.id)
      const { code, msg } = await updateMessageTypeSort({
        ids
      })
      if (code !== 0) {
        this.$message.error(msg)
        return
      }
      this.handleClose()
      this.$emit('success')
    }
  }
}
</script>

<style lang="scss" scoped>
    .title-list {
        background:#fff;
        margin:100px auto 0;
        border: 1px solid red;

        .audit-project {

        }
        .dialog-footer {
            margin-top: 20px;
            text-align: center;
        }

    }
</style>
